package cn.yunhe.control;

import cn.yunhe.entity.Vote;
import cn.yunhe.server.VoteServaer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/VoteServletSelect")
public class VoteServletSelect extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        VoteServaer voteServaer = new VoteServaer();
        List<Vote> list = voteServaer.selectAll(); //获取所有投票结果
        if (list!=null&&list.size()>0){
            request.setAttribute("result",list);
            request.getRequestDispatcher("count.jsp").forward(request,response);
        }else {
            request.setAttribute("result","暂时没有投票结果!!");
            request.getRequestDispatcher("vote.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
